﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Frame.Pages;
using DevExpress.Web.ASPxGridView;


public partial class EditConsumerHisDetail : Frame.Pages.FliterBIEditBasePage<DAL.BLI_ConsumerHisDetail>
{
    protected override Func<DAL.BLI_ConsumerHisDetail, bool> FliterExpression
    {
        get
        {
            if (string.IsNullOrEmpty(Request.QueryString["BookNo"]))
            {
                return new Func<BLI_ConsumerHisDetail, bool>(o => false);
            }
            return new Func<BLI_ConsumerHisDetail, bool>(o => o.BookNo == Request.QueryString["BookNo"]);
        }
    }
    /// <summary>
    /// 权限编码，需要重新设置
    /// </summary>
    protected override string ActionID
    {
        get { return "0"; }
    }
    protected void gridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        e.NewValues["BookNo"] = RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.BookNo;
    }

    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!IsPostBack && !IsCallback)
        {
            if (Frame.Pages.RefrenceContext<DAL.BI_Consumer>.Current != null)
            {
                WebUtility.MappingConsumerView(Detailpanel, RefrenceContext<DAL.BI_Consumer>.Current.Model);
            }
            BackLink.NavigateUrl = (Frame.Pages.RefrenceContext<DAL.BLI_ConsumerHis>.Current != null ?
         Frame.Pages.RefrenceContext<DAL.BLI_ConsumerHis>.Current.BackUrl : "");
            if (RefrenceContext<DAL.BLI_ConsumerHis>.Current!= null)
            {
                this.View_BookNo.Text = RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.BookNo;
                this.View_ConsumerDate.Text = RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.ConsumerDate.ToShortDateString();
                this.View_Money.Text = RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.Money.ToString("f2");
                using (DAL.CMSDALDataContext Dcontext = new CMSDALDataContext())
                {
                    BI_ConsumePeriod Period = Dcontext.BI_ConsumePeriod
                        .FirstOrDefault(o => o.PeriodID == RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.Period_ID);
                    this.View_Preiod.Text =
                        (Period == null ? RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.Period_ID.ToString()
                        : Period.PeriodName);
                    //BI_ConsumeType ConsumeType = Dcontext.BI_ConsumeType
                    //        .FirstOrDefault(o => o.ConsumeTypeID == RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.ConsumeType_ID);
                    //this.View_ConsumerType.Text =
                    //    (ConsumeType == null ? RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.ConsumeType_ID.ToString()
                    //    : ConsumeType.ConsumeTypeName);
                }

                this.View_TableCount.Text = RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.TableCount.ToString();
                this.View_HisRemark.Text = RefrenceContext<DAL.BLI_ConsumerHis>.Current.Model.Remark;
            }

        }
    }
    string ConsumeNo=string.Empty;
    protected void DgridView_Load(object sender, EventArgs e)
    {
        ASPxGridView grid = sender as ASPxGridView;
        Frame.Global.GlobalFunctions.SetGridView(grid, true);
        Frame.Global.GlobalFunctions.AddGridViewEvent(grid);
        ConsumeNo = grid.GetMasterRowKeyValue().ToString();
        grid.DataBind();
    }
    protected void DLSMDSourceMain_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
    {
        e.KeyExpression = "HisListID";
        DAL.CMSDALDataContext Dcontext = new CMSDALDataContext();
        e.QueryableSource = Dcontext.BLI_ConsumerHisList.Where(o => o.ConsumeNo == ConsumeNo);
    }
    protected void DgridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        e.NewValues["ConsumeNo"] = ConsumeNo;
    }
}